package com.jsz.peini.service.report;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

import com.jsz.peini.bean.report.ReportImage;
import com.jsz.peini.bean.report.ReportInfo;
import com.jsz.peini.common.util.FileUtils;
import com.jsz.peini.mapper.report.ReportInfoMapper;

@Service
public class ReportInfoService {
	
	@Resource
	private ReportInfoMapper ReportInfoMapper;
	
	public int insertByType(ReportInfo reportInfo) {
		int questionNum = ReportInfoMapper.insertByType(reportInfo);
		return questionNum;
	}

	public ReportInfo selectById(String userId){
		ReportInfo reportInfo=ReportInfoMapper.selectById(userId);
		return reportInfo;
	}
	
	public int insertById(ReportImage reportImage){
		int Report=ReportInfoMapper.insertById(reportImage);
		return Report;
	}
	
	@Transactional
	public Integer setQuestion(ReportInfo reportInfo,CommonsMultipartFile[] file){
		ReportInfoMapper.insertSelective(reportInfo);
		//int reportInfoNum=questionService.insertByType(reportInfo);
		//if (reportInfoNum>0&&file!=null) {
		String reportImgs = "";
		if (file!=null) {
			
			ReportInfo reportInfo2=selectById(reportInfo.getUserId());
			String filePath = "/upload/question/";
			for(MultipartFile fileMap : file){
				// 判断文件是否为空  
		        if (!fileMap.isEmpty()) {
		        	String resultPath = FileUtils.uploadFile(fileMap, filePath);
					reportImgs += resultPath + ",";
					
					/*ImgVo imgVo = new ImgVo();
					imgVo.setImgUrl(resultPath);
					imgVo.setParamId(reportInfo.getId().toString());
					imgVo.setType(3);
					RedisUtil.lpush(RedisConstants.IMG_CHECK.getBytes(), SerializeUtil.serialize(imgVo));*/
		        }
			}
		}	
		reportInfo.setReportImgs(reportImgs);
		//questionService.insertByType(reportInfo);
		ReportInfoMapper.updateByPrimaryKeySelective(reportInfo);
		return null;
	}

}
